﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UReturn500VisitAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "UReturnVisitList"; }
        }
        private UWarrantyCardInfo _obj;
        protected UWarrantyCardInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = UWarrantyCardController.GetByUWCID(UWCID);
                return _obj;
                //OMenuController.ge
            }
        }
        /// <summary>
        /// 需要修改的ID
        /// </summary>
        protected int UWCID
        {
            get
            {
                return GetRequestValue<int>("UWCID");
            }
        }

        protected string AgentName
        {
            get
            {
                return GetRequestValue<string>("AgentName","");
            }
        }

        protected string VisitType
        {
            get
            {
                return GetRequestValue<string>("VisitType","8");
            }
        }

        protected string GetTimer()
        {
            if (VisitType == "8")
                return "1";
            if (VisitType == "70")
                return "2";
            if (VisitType == "130")
                return "3";
            return "";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();

            }
        }

        private void addmenu()
        {
            UReturn500VisitInfo obju = Request.SerializableObject<UReturn500VisitInfo>();


            U4008RecordInfo obj2 = new U4008RecordInfo();
            obj2.UserName = GetRequestValue<string>("dwz.orgLookup.UserName", "");
            if (!string.IsNullOrEmpty(obj2.UserName))
            {
                if ((!string.IsNullOrEmpty(obju.otherRemark) ))//如果没做50小时养,或有其它问题
                {
                    string Problemdescription =string.Format("{0}第{1}天回访问题",obj.SerialNumber,VisitType);
                 
                   
                    if (!string.IsNullOrEmpty(obju.otherRemark))
                        Problemdescription += obju.otherRemark;

                    obj2.URType = "回访问题";
                    obj2.SerialNumber = obj.SerialNumber;
                    //obj2.UserName = GetRequestValue<string>("dwz.orgLookup.UserName", "");
                    obj2.CallDate = DateTime.Now;
                    obj2.WorkAddress = "";
                    obj2.WorkHours = obju.WorkTime.ToString();
                    obj2.Problemdescription = Problemdescription;
                    obj2.CustomerTel = obj.CustomerMobile;
                    obj2.AgentName = obj.AgentName;
                    obj2.U4RID = U4008RecordController.Add(obj2);
                }
            }
            obju.U4RID = obj2.U4RID;     
            //
            AddLog(Permission.新增, obju);

            if (UReturn500VisitController.Add(obju)>0)
            {
                SuccessJson("添加成功", this.DWZRef);
            }
            else
                ErrorJson("添加失败", this.DWZRef);
        }
    }
}